/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projekdb;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author localhost
 */
public class dataSurat {
        public Vector surat = new Vector();
        public Vector label = new Vector();
	private dbSurat Mb;

	public dataSurat() throws SQLException
	{
		setSurat("");
	}

    public dataSurat(String id) throws SQLException
	{
		setSurat(id);
	}

	public void setSurat(String id) throws SQLException
	{

		Mb = new dbSurat();
		ResultSet rsSurat = Mb.select(id);

		this.surat.removeAll(surat);
                this.label.removeAllElements();


                for (int i = 0; i<rsSurat.getMetaData().getColumnCount();i++)
                {
                    this.label.add(rsSurat.getMetaData().getColumnLabel(i+1));
                }

		try {
			while (rsSurat.next())
			{
                            Vector rowVector = new Vector();

                            for (int i = 0; i<rsSurat.getMetaData().getColumnCount();i++)
                            {
                                rowVector.add(rsSurat.getObject(i+1));
                            }

                            this.surat.add(rowVector);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

        public Vector<surat> getMahasiswa()
        {
            return this.surat;
        }
        
        public Vector getLabels()
        {
            return this.label;
        }

	public void addSurat(String noSurat, String tanggal, String tujuan, String keperluan, String ket)
	{
		surat NB=new surat(noSurat,tanggal,tujuan,keperluan,ket);
        this.Mb.insert(NB);
	}

    public void delSurat(String noSurat)
	{
		this.Mb.delete(noSurat);
	}

    public void updSurat(String noSurat, String tanggal, String tujuan, String keperluan, String ket)
	{
		this.Mb.update(noSurat, tanggal, tujuan, keperluan, ket);
	}

}
